<xsl:stylesheet version="1.0"	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                xmlns:str="http://exslt.org/strings"
                                extension-element-prefixes="str">

<xsl:import href="str.xsl" />

<xsl:output method="xml" omit-xml-declaration="yes"/>

<!--	<xsl:include href="preferences.xsl"/>   -->
<!-- line 169 controls displayed episode plot length -->
<!-- line 1130 controls episode plot length put into html -->
	<!-- Needed Templates -->

	<xsl:template name="get-js">
	<script type="text/javascript">
	  <xsl:comment>

    var focusId=false;
    var url = false;
    var playListActive = false;
    var toggleShow = new Array();
    var fMoved = false;

    var sPlotPiece = '';
    var iPlotPage = 1;
    var iPages = 1;
    var iMaxChars = 420;
    var aiPlotStart = new Array();
    var aiPlotEnd = new Array();
    var fInfos = false;
    var fTrailer = false;
    var fPlot = true;
    var fTvShow = false;
    var sLastActiveTab = 'plot';
    var fScrollEpisodePlot = false;
    var sPlot = '';

    // 2009-05-29: change pages if true
    var fPlay = false;


    // in here all hidden Objects are saved
    var asShowHide = new Object();
    var asClasses = new Object();
    asShowHide['box'] = true;
    asShowHide['videoSource'] = true;
    asShowHide['videoInfo'] = true;

    <xsl:if test="top250 != -1">
    	asShowHide['top250'] = true;
    </xsl:if>


    <xsl:if test="season = -1">
      asShowHide['plot'] = true;
      asShowHide['audioInfo'] = true;
    </xsl:if>

    var fEpisodeList = false;

    <!-- TV SHOW JS -->
    <xsl:if test="season != -1">
      var iEpisodesPerPage = <xsl:value-of select="$iEpisodesPerPage"/>;
      var iEpisodesLength = asEpisodePlot.length - 1;

      <xsl:if test="$tooManySeries = 'true'">
		  var iPagesEpList = Math.floor(iEpisodesLength / iEpisodesPerPage);
		  if ((iEpisodesLength % iEpisodesPerPage) <![CDATA[>]]> 0 )
		  {
		    iPagesEpList = iPagesEpList  +1;
		  }
	    </xsl:if>
	    var fLastLinkFocused = false;
		  var fFirstLinkFocused = true;
		  var fFirstCall = true;

      var episodeId = 1;
	    var episodeName = 1;
	    var showEpisdoeInfos = true;
	    var sIdLinkPrefix = 'a_e_';
	    var sIdSpanPrefix = 's_e_';
	    var sIdTvPrefix = 't_e_';
	    var iCnt = 0;
	    var iMaxChars = 540;

      asShowHide['audioInfoTv'] = true;
      fEpisodeList = true;
	    fTvShow = true;
	    fPlot = false;
	    sLastActiveTab = 'tvshow';

	    <xsl:choose>
		    <xsl:when test="$mjb.includeVideoImages='true'">
					var fUseTvImages = true;
		   	</xsl:when>
		   	<xsl:otherwise>
		   		var fUseTvImages = false;
		   	</xsl:otherwise>
    	</xsl:choose>
	    var showPlotwithBtn = false;
	    <xsl:if test="$showPlotwithBtn = 'true'">
	    	showPlotwithBtn=true;
	    </xsl:if>
	    var iEpisodeId=1;
	    var iFirstEpisodeId = 1;
	  	var iLastEpisodeId = iEpisodesLength;
	    var iLastPageId = 1;

	    var fEpisodeInfo = false;
    </xsl:if>


	</xsl:comment>
	</script>


  <xsl:if test="season != -1">

  <script type="text/javascript">
  <xsl:comment>
		var setFocusId = function(x)
		{
			focusId = sIdLinkPrefix + x;
		},

    setEpisodeUrl = function(x)
		{
			var y = iCnt + x;
			url = buildUrl(y);
			document.getElementById('openEpisode').setAttribute("href",url);
		},

    showEpisode = function(iElId, showInfos)
    {
      var x = iElId;
      var y = Math.floor(iCnt) + Math.floor(x);

      if (fFirstLinkFocused <![CDATA[&&]]> iElId != 1)
        fFirstLinkFocused = false;

      if (fLastLinkFocused <![CDATA[&&]]> iElId != iLastId)
        fLastLinkFocused = false;

      // ReverseOrder
      <xsl:if test="$doReverseEpisodes = 'true'">
		  var y = Math.floor(iEpisodesLength - iCnt - x +1);
      </xsl:if>

    	setFocusId(y);
      setEpisodeUrl(x);
    	iEpisodeId = x;

      if (showPlotwithBtn == true <![CDATA[&&]]> typeof showInfos == 'undefined' )
      	return true;

      if (showEpisdoeInfos )
        showItem('episodenInfos');

      fEpisodeInfo = true;

    	if ( episodeId == 1 )
      {
        episodeId = document.getElementById('episodeId');
      }

      if (asEpisodePlot[y].length <![CDATA[<=]]> 530)
      {
        episodeId.firstChild.nodeValue = asEpisodePlot[y];
        fScrollEpisodePlot = false;
      }

      else
      {
        sPlot = asEpisodePlot[y];
        iMaxChars = 485;
        aiPlotStart = new Array();
        splitPlot();
        iPages = aiPlotStart.length;
        showPlotPiece(1);
        fScrollEpisodePlot = true;
      }
      showItem('episodePages');


      if ( episodeName == 1 )
      {
        episodeName = document.getElementById('episodeName');
      }
      episodeName.firstChild.nodeValue = asEpisodeTitle[y];

      <xsl:if test="season != -1  and $mjb.includeVideoImages='true' ">
      if (typeof asEpisodeImage[y] != 'undefined' <![CDATA[&&]]> asEpisodeImage[y] != 'UNKNOWN' <![CDATA[&&]]> asEpisodeImage[y] != '')
      {
     	  showItem('episodeImgBack');
     	  showItem('episodeImg');
      	document.getElementById('episodeImg').setAttribute("src",asEpisodeImage[y]);
      }
      else
      {
      	hideItem('episodeImgBack');
      	hideItem('episodeImg');
      }
			</xsl:if>
    },

    hideEpisode = function(x)
    {
      if (asShowHide['episodenInfos'] == false)
        return false;

      if ( episodeId == 1 )
        episodeId = document.getElementById('episodeId');
      episodeId.firstChild.nodeValue = "";
      if ( episodeName == 1 )
        episodeName = document.getElementById('episodeName');
      episodeName.firstChild.nodeValue = "";

      if (fEpisodeInfo)
        hideItem('episodenInfos');

      focusId=false;

      <xsl:if test="season != -1  and $mjb.includeVideoImages='true' ">
      if (fEpisodeInfo)
      {
      	hideItem('episodeImgBack');
      	hideItem('episodeImg');
      	hideItem('episodePages');
      }
			</xsl:if>
			fScrollEpisodePlot = false;

			fEpisodeInfo = false;

    },

		/*
		* sets the focus to the given
		*/
		setFocus = function(x)
		{
		  if (x == 'first')
		  	x = iFirstEpisodeId;
		  else if (x == 'last')
		  	x = iLastEpisodeId;

			setFocusId(x);
		  document.getElementById(focusId).focus();
		  showEpisode(x);
		},

		/*
		* toggles Episode details on/off
		* is only needed, if showPlotwithBtn is set to true
		*/
		toggleEpisodeDetails = function()
		{
			if (typeof asShowHide['episodenInfos'] == 'undefined' || asShowHide['episodenInfos'] == false )
				showEpisode(iEpisodeId, true);
			else
				hideEpisode(iEpisodeId);
		},

		/*
		* scroll episode-list "pages" up and down
		* is only needed, if more episodes than iEpisodesPerPage are present
		* @var boolean		if true, episodes n + iEpisodesPerPage are activated
		*/
		scrollLinks = function(down)
	  {

		  var iLoop = iEpisodesPerPage;

  		if (typeof down == 'undefined')
  			iCnt = Math.floor(iCnt - iLoop);
  		else
  			iCnt = Math.floor(iCnt + iLoop);

  		var iPage = iCnt / iEpisodesPerPage +1;

  		// page 1
			if (iCnt == 0)
			{
				fLastLinkFocused = false;
			  fFirstLinkFocused = false;
			}
  		else if (iCnt <![CDATA[<]]> 0) // page -1
			{
			  if (!fFirstLinkFocused)
			  {
  				iCnt = Math.floor(iCnt + iLoop);
  				// set focus to first episode
  				setFocus(1);
  				fFirstLinkFocused = true;
  				return false;
  			}
  			else
  			{
  			  iCnt = iEpisodesLength - (iEpisodesLength - iLoop);
  			  iPage = iCnt / iEpisodesPerPage +1;
  			  fFirstLinkFocused = true;
  			  fLastLinkFocused = false;
  			}
			}
			else if (iCnt +1 <![CDATA[>]]> iEpisodesLength) //last page +1
			{
			  if (!fLastLinkFocused)
			  {
  				iCnt = Math.floor(iCnt - iLoop);
  				// set focus to last episode
  				setFocus(iEpisodesLength - iCnt);
  				fLastLinkFocused = true;
  				return false;
  			}
  			else
  			{
  			  iCnt = 0;
  			  iPage = 1;
  			  fLastLinkFocused = false;
  			  fFirstLinkFocused = true;
  			}
			}
			else if (Math.floor(iCnt + iLoop) <![CDATA[>=]]> iEpisodesLength) // last page
			{
				fLastLinkFocused = false;
			  fFirstLinkFocused = false;
			}
			else //all pages between 1 and last
			{
			  fLastLinkFocused = false;
			  fFirstLinkFocused = false;
			}
			//console.log(iCnt);

			document.getElementById('pageCount').firstChild.nodeValue = ' ' + iPage + ' / ' + iPagesEpList + ' (' + iEpisodesLength + ')';

			var iLastId = 0;

		  for (var i = 1; i <![CDATA[<=]]> iLoop; i++)
	  	{
	  	  var iElId = i;
	  	  var sLinkId = sIdLinkPrefix + iElId;
	  	  var sSpanId = sIdSpanPrefix + iElId;
	  	  var sTvId = sIdTvPrefix + iElId;


	  	  var elLink = document.getElementById(sLinkId);
	  		var elSpan = document.getElementById(sSpanId);
	  		var elTvID = document.getElementById(sTvId);
	  		<xsl:if test="$doReverseEpisodes = 'true'">
  		  var no = Math.floor(iEpisodesLength - iCnt - i +1);
  		  if (no <![CDATA[<]]> 1)
  			{
					iLastId = i;
  				elLink.setAttribute("class",'hidden');
					elSpan.setAttribute("class", 'hidden');
		  		elTvID.setAttribute("class",'hidden');
		  		asShowHide[sLinkId] = false;
		  		asShowHide[sSpanId] = false;
		  		asShowHide[sTvId] = false;
  			}
        </xsl:if>
        <xsl:if test="$doReverseEpisodes != 'true'">
  		  var no = Math.floor(iCnt + i);

  			if (no <![CDATA[>]]> iEpisodesLength)
  			{
					iLastId = i;
  				elLink.setAttribute("class",'hidden');
					elSpan.setAttribute("class", 'hidden');
		  		elTvID.setAttribute("class",'hidden');
		  		asShowHide[sLinkId] = false;
		  		asShowHide[sSpanId] = false;
		  		asShowHide[sTvId] = false;
		  		iLastPageId = 0;
  			}
  			</xsl:if>
  			else
  			{
  			  if (i > iLastPageId)
  			  {
  			   iLastPageId = i;
  			  }
		  		elLink.setAttribute("href",buildUrl(no));
		  		var iEpisodeNo = asEpisodeNo[no];
		  		if (iEpisodeNo &lt; 10)
		  		  iEpisodeNo = '0' + iEpisodeNo;
	  			var sSpanValue =iEpisodeNo + '. ' + asEpisodeTitleShort[no];

		  		<xsl:if test="$show_episode_names!='true'">
		  		  var sSeason = <xsl:value-of select="/details/movie/season" />;
  		  		if (sSeason &lt; 10)
  		  		  sSeason = '0' + sSeason;
		  			var sSpanValue =  's' + sSeason + 'e'+ iEpisodeNo;
		  		</xsl:if>

		  		elSpan.firstChild.nodeValue=sSpanValue;
		  		elTvID.setAttribute("TVID",asEpisodeNo[no]);

		  		if (asShowHide[sLinkId] == false)
		  		{
		  			elLink.setAttribute("class",'TvLink');
						elSpan.setAttribute("class", 'tabTvShow');
			  		elTvID.setAttribute("class",'tabTvShow');
			  		asShowHide[sLinkId] = true;
  		  		asShowHide[sSpanId] = true;
  		  		asShowHide[sTvId] = true;
		  		}
		  	}
	  	}

	  	if (typeof down == 'undefined' <![CDATA[&&]]> iLastPageId <![CDATA[>]]> 0)
	  	{
	  	  // litte timeout is needed - caused by dramaqueen gaya
	  	  window.setTimeout("setFocus(iLastPageId)", 1);
	  	}
	  	else
	  	  setFocus(1);
	  },



	  /*
		* show or hides the node with the given id
		*/
	  showhideEpisode = function(id, hide)
	  {

      if (typeof asShowHide[id] == 'undefined' || asShowHide[id] == true || hide == true )
        var fHide = true;
      else
        var fHide = false;

      if (fHide == false)
      {
        showItem(id)
      }
      else
      {
        fScrollEpisodePlot = false;
        hideItem(id)
      }
    },
    buildUrl = function(no)
    {
      return '<xsl:value-of select="$filePath" />' + asEpisodeUrl[no];
    };
    </xsl:comment>
	  </script>
    </xsl:if>
    <!--  END TV SHOW JS -->
    <!--  END TV SHOW JS -->
    <!--  END TV SHOW JS -->
    <script type="text/javascript">
    <xsl:comment>
    var fAllhiden = false;

    var showItem = function(id)
    {
      // if item is visible, there is nothing to do
      if (asShowHide[id] == true)
        return;

      if ( typeof asShowHide[id] == 'undefined' )
       asClasses[id] = document.getElementById(id).getAttribute('class');

      if ( typeof asClasses[id] != 'undefined' <![CDATA[&&]]> typeof asShowHide[id] != 'undefined' <![CDATA[&&]]> asClasses[id] != 'hidden' )
        var sClass = asClasses[id];
      else
        var sClass = 'visible';

      asShowHide[id] = true;
      document.getElementById(id).setAttribute('class',sClass);
    },

    hideItem = function(id)
    {

      // if item is hidden, there is nothing to do
      if (asShowHide[id] == false)
        return;

      var sClass = 'hidden';
      if ( typeof asClasses[id] == 'undefined' )
        asClasses[id] = document.getElementById(id).getAttribute('class');

      asShowHide[id] = false;
      document.getElementById(id).setAttribute('class',sClass);
    },

    hideAll = function()
    {
      for (var id in asShowHide)
      {
        if (fAllhiden == false)
        {
          if (asShowHide[id] == true)
            hideItem(id);
          else
            asShowHide[id] = true;
        }
        else
        {
          if (asShowHide[id] == false)
            showItem(id);
          else
            asShowHide[id] = false;
        }

      }

      if (fAllhiden == false)
      {

        if (sLastActiveTab == 'plot')
          hidePlot();
        else if (sLastActiveTab == 'infos')
          hideInfos();
        else if (sLastActiveTab == 'tvshow')
          hideTvShow();
        else
          hideTrailer();

        <xsl:if test="season != -1">
        if (!fTvShow)
          document.styleSheets[1].cssRules[5].style.visibility="hidden";
    	  </xsl:if>

    	  fAllhiden = true;

      }

      else
      {


        if (sLastActiveTab == 'plot')
          showPlot();
        else if (sLastActiveTab == 'infos')
          showInfos();
        else if (sLastActiveTab == 'tvshow')
          showTvShow();
        else
          showTrailer();

        <xsl:if test="season != -1">
        if (!fTvShow)
          document.styleSheets[1].cssRules[5].style.visibility="visible";
    	  </xsl:if>

        fAllhiden = false;
      }
    },

    showPlot = function ()
    {
      document.styleSheets[1].cssRules[0].style.visibility="visible";

      hideInfos();
      hideTrailer();
      <xsl:if test="season != -1">
      document.getElementById('tabPlot').focus();
      hideTvShow();
  	  </xsl:if>
      hideShowDiverses();
      document.getElementById('tabPlotImg').setAttribute('src', 'pictures/tab_plot_f3.png');
      document.getElementById('tabInfosImg').setAttribute('src', 'pictures/tab_infos.png');
      <xsl:if test="count(extras) != 0 and /details/movie/season = -1">
      document.getElementById('tabTrailerImg').setAttribute('src', 'pictures/tab_trailer.png');
      </xsl:if>

      fPlot = true;
      <xsl:if test="season != -1">
      iMaxChars = 420;
      sPlot = sPlotLong.replace(/\s\s+/g, ' ');
      aiPlotStart = new Array();
      splitPlot();
      document.getElementById('tabTvShowImg').setAttribute('src', 'pictures/tab_tvshow.png');
      iPages = aiPlotStart.length;
      showPlotPiece(1);
  	  </xsl:if>


      sLastActiveTab = 'plot';
      fScrollEpisodePlot = false;
    },

    hidePlot = function ()
    {
      document.styleSheets[1].cssRules[0].style.visibility="hidden";
      fPlot = false;
    },
    hideInfos = function ()
    {
      document.styleSheets[1].cssRules[1].style.visibility="hidden";
      fInfos = false;
    },
    hideTrailer = function ()
    {
      document.styleSheets[1].cssRules[2].style.visibility="hidden";
      fTrailer = false;
    },
    hideTvShow = function ()
    {
      document.styleSheets[1].cssRules[4].style.visibility="hidden";
      hideEpisode();
      fTvShow = false;
    },

    hideShowDiverses = function (show)
    {
      // show them
      if (typeof show == 'undefined')
      {
        if (fEpisodeList)
        {
          document.styleSheets[1].cssRules[5].style.visibility="visible";
          fEpisodeList = false;
        }
        else
         return true;
      }
      else //hide them
      {
        if (!fEpisodeList)
        {
          document.styleSheets[1].cssRules[5].style.visibility="hidden";
          fEpisodeList = true;
        }
        else
         return true;
      }

    },

    showInfos = function ()
    {
      hidePlot();
      hideTrailer();
      <xsl:if test="season != -1">
      hideTvShow();
  	  </xsl:if>
      hideShowDiverses();

      document.styleSheets[1].cssRules[1].style.visibility="visible";

      document.getElementById('tabInfosImg').setAttribute('src', 'pictures/tab_infos_f3.png');
      document.getElementById('tabPlotImg').setAttribute('src', 'pictures/tab_plot.png');
      <xsl:if test="count(extras) != 0 and /details/movie/season = -1">
      document.getElementById('tabTrailerImg').setAttribute('src', 'pictures/tab_trailer.png');
      </xsl:if>

      <xsl:if test="season != -1">
      document.getElementById('tabTvShowImg').setAttribute('src', 'pictures/tab_tvshow.png');
  	  </xsl:if>
  	  fScrollEpisodePlot = false;


      fInfos = true;
      sLastActiveTab = 'infos';
    },

    showTrailer = function ()
    {
      hidePlot();
      hideInfos();
      <xsl:if test="season != -1">
      hideTvShow();
  	  </xsl:if>

      hideShowDiverses();
      document.styleSheets[1].cssRules[2].style.visibility="visible";

      document.getElementById('tabTrailerImg').setAttribute('src', 'pictures/tab_trailer_f3.png');
      document.getElementById('tabPlotImg').setAttribute('src', 'pictures/tab_plot.png');
      document.getElementById('tabInfosImg').setAttribute('src', 'pictures/tab_infos.png');
      fTrailer = true;
      sLastActiveTab = 'trailer';
      document.getElementById('tabTrailer').focus();

    },

    showTvShow = function ()
    {
      hidePlot();
      hideInfos();
      hideShowDiverses(true);
      document.styleSheets[1].cssRules[4].style.visibility="visible";
      if (!fFirstCall)
        window.setTimeout("setFocus(1)", 1);

      document.getElementById('tabTvShowImg').setAttribute('src', 'pictures/tab_tvshow_f3.png');
      document.getElementById('tabPlotImg').setAttribute('src', 'pictures/tab_plot.png');
      document.getElementById('tabInfosImg').setAttribute('src', 'pictures/tab_infos.png');
      fTvShow = true;
      sLastActiveTab = 'tvshow';
    },

    plotDown = function()
    {
      if (iPages <![CDATA[<]]> 2)
        return false;
      else if (iPlotPage +1 <![CDATA[>]]> iPages)
      {
        iPlotPage = 0;
        plotDown();
      }
      else
      {
        iPlotPage = iPlotPage +1;
        showPlotPiece(iPlotPage);
      }
    },

    plotUp = function()
    {
      if (iPages <![CDATA[<]]> 2)
        return false;
      else if (iPlotPage - 1 <![CDATA[<]]> 1)
      {
        iPlotPage = iPages +1;
        plotUp();
      }
      else
      {
        iPlotPage = iPlotPage -1;
        showPlotPiece(iPlotPage);
      }
    },

    splitPlot = function(iCnt)
    {
      if (sPlot.length <![CDATA[<=]]> iMaxChars)
      {
        iPages = 1;
        return true;
      }

      if (typeof aiPlotStart[0] == 'undefined')
      {
        aiPlotStart[0] = 0;
      }

      if (typeof iCnt == 'undefined')
      {
        var iCnt = 0;
      }

      var iStart = iMaxChars;
      if (typeof aiPlotStart[iCnt] != 'undefined')
      {
        iStart = aiPlotStart[iCnt] + iMaxChars;
      }

      for (var t=0; t<![CDATA[<]]>100; t++)
      {
        var iEnd = iStart + 1;

        if (iEnd <![CDATA[<]]> sPlot.length)
        {
          if (sPlot.substring(iStart, iEnd) == " ")
          {
            // treffer - leerzeichen gefunden
            aiPlotEnd[iCnt] = iStart;

            if (iEnd + iMaxChars <![CDATA[>=]]> sPlot.length)
            {
              aiPlotStart[iCnt +1] = iEnd;
              aiPlotEnd[iCnt +1] = sPlot.length;
            }
            else
            {
              aiPlotStart[iCnt +1] = iEnd;
            }

            break;
          }
          else
          {
            iStart = iStart +1;

          }
        }
        else
        {
          aiPlotEnd[iCnt] = sPlot.length;

          break;
        }
      }

      if (iEnd <![CDATA[<]]> sPlot.length)
      {
        splitPlot(iCnt +1);
      }
    },

    init = function()
    {


      <xsl:if test="season = -1">
        sPlot = sPlotLong.replace(/\s\s+/g, ' ');
        splitPlot();
        iPages = aiPlotStart.length;
        showPlot();
        showPlotPiece(1);
    	</xsl:if>
    	<xsl:if test="season != -1">
    	showTvShow();
    	hideItem('episodePages');
    	fFirstCall = false;
    	</xsl:if>

    	<xsl:if test="season != -1 and $tooManySeries='true'">
    	document.getElementById('pageCount').firstChild.nodeValue = '1' + ' / ' + iPagesEpList + ' (' + iEpisodesLength + ')';
    	</xsl:if>

    	<xsl:if test="$showPosterAtStart = 'true' and $useAnimation='false'">
    	togglePoster();
    	</xsl:if>

    },
    pageDown = function()
		{
		  //alert(fPlay);
		  if (fScrollEpisodePlot || fTvShow)
		    clickDown();
			else
        nextPage();
		},
		pageUp = function()
		{
		  if (fScrollEpisodePlot || fTvShow)
		    clickUp();
			else
        previousPage();
		},
		nextPage = function()
		{
		  //document.getElementById('nextMovie').focus();
		  var jumpurl = document.getElementById('nextMovie').href;
		  location.assign(jumpurl);
		},
		previousPage = function()
		{
      var jumpurl = document.getElementById('previousMovie').href;
		  location.assign(jumpurl);
		},
    clickDown = function()
    {
      if (fPlot || fScrollEpisodePlot)
        plotDown();
			else if(fTvShow)
			{
			  <xsl:choose>
	        <xsl:when test="$tooManySeries='true'">
            scrollLinks(true);
				 	</xsl:when>
				 	<xsl:otherwise>
				 		setFocus('last');
				 	</xsl:otherwise>
				</xsl:choose>
			}
			else
			  return false;

		},
		clickUp = function()
    {
      if (fPlot || fScrollEpisodePlot)
        plotUp();
			else if(fTvShow)
			{
			  <xsl:choose>
	        <xsl:when test="$tooManySeries='true'">
            scrollLinks();
				 	</xsl:when>
				 	<xsl:otherwise>
				 		setFocus('first');
				 	</xsl:otherwise>
				</xsl:choose>
			}
			else
			  return false;
		},
    showPlotPiece = function(iPage)
    {
      var iCnt = iPage - 1;
      if (typeof aiPlotStart[iCnt] != 'undefined')
      {
        var sPlotpiece = sPlot.substring(aiPlotStart[iCnt], aiPlotEnd[iCnt]);
        if (iPage <![CDATA[<]]> iPages)
          sPlotpiece = sPlotpiece + ' ...';

        if (fPlot)
        {
        	document.getElementById('plot').firstChild.nodeValue = sPlotpiece;
          document.getElementById('plotInfo').firstChild.nodeValue = iPage +' / '+ iPages;
        }
        else if (fTvShow)
        {
          document.getElementById('episodeId').firstChild.nodeValue = sPlotpiece;
          document.getElementById('episodePages').firstChild.nodeValue = iPage +' / '+ iPages;
        }
      }
      else
        return false;
    };



		</xsl:comment>
		</script>

		<script type="text/javascript">
		<xsl:comment>
		// animation vars
    var fFirstRun = true;
    var iImgX = <xsl:value-of select="$posters.width" />;
    var iPosXStart = 500;
    var iPosX = 0;
    var iZoomX = 0;
    var iStep = 50;
    var elImage = false;
    var elImageDiv = false;
    var fZoomIn = false;
    var fZoomOut = false;

    var fUseAnimation = <xsl:value-of select="$useAnimation" />;

		var zoomIn = function()
    {

      zoomInit();

      if (!fZoomIn)
      {
        elImageDiv.setAttribute('class', 'abs poster');
        fZoomIn = true;
        fZoomOut = false;
      }

      if (iZoomX <![CDATA[>]]>= iImgX)
        return false;

      if (iZoomX + iStep <![CDATA[<]]> iImgX)
        iZoomX = iZoomX + iStep;
      else
        iZoomX = iImgX;

      setImagePos();

      if (iZoomX + iStep <![CDATA[<]]> iImgX)
			{
      	window.setTimeout("zoomIn()", 0);
			}
			else
			{
			  iZoomX = iImgX;
        setImagePos();
			}
    },
    zoomOut = function()
    {
      zoomInit();

      if (!fZoomOut)
      {

        fZoomIn = false;
        fZoomOut = true;
      }

      if (iZoomX == 0)
        return false;

      if (iZoomX - iStep <![CDATA[>]]> 0)
        iZoomX = iZoomX - iStep;
      else
        iZoomX = 0;

      setImagePos();

      if (iZoomX - iStep <![CDATA[>]]> 0)
			{
      	window.setTimeout("zoomOut()", 0);
			}
			else
			{
			  iZoomX = 0;
        setImagePos(0);
        elImageDiv.setAttribute('class', 'abs poster hidden');
        window.setTimeout("hideAll()", 0);
			}
    },
    setImagePos = function()
    {
      elImage.setAttribute("width",iZoomX);
      elImage.setAttribute("height",0);

      if (iZoomX <![CDATA[>]]> 0)
      {
        if (fZoomIn)
        {
          iPosX = Math.round(iPosX - iStep/2);
        }
        else
        {
          iPosX = Math.round(iPosX + iStep/2);
        }
      }
      else
      {
        iPosX = iPosXStart;
      }

      document.styleSheets[1].cssRules[6].style.left = iPosX + 'px';
    },
    togglePoster = function()
    {

      if (fUseAnimation)
      {
        if (fFirstRun || fZoomOut)
        {
          hideAll();
          zoomIn();
        }
        else
        {
          zoomOut();
          //window.setTimeout("hideAll()", 1000);

        }

      }
      else
      {
        if (fFirstRun || fZoomOut)
          showPoster();
        else
          hidePoster();
      }


    },
    showPoster = function()
    {
      elImageDiv = document.getElementById('imageDiv');
      elImageDiv.setAttribute('class', 'abs poster');
      fFirstRun = false;
      fZoomOut = false;
    },
    hidePoster = function()
    {
      elImageDiv = document.getElementById('imageDiv');
      elImageDiv.setAttribute('class', 'abs poster hidden');
      fZoomOut = true;
    },

    zoomInit = function()
    {
      if (fFirstRun)
      {
				elImage = document.getElementById('image');
				elImageDiv = document.getElementById('imageDiv');
				iPosX = iPosXStart;
				fFirstRun = false;
      }
    };
    </xsl:comment>
		</script>
	</xsl:template>

	<xsl:template name="get-episode-infos">
		<xsl:variable name="teiler">
        	<xsl:choose>
      			<xsl:when test="round((count(/details/movie/files/file)+4) div 10) &gt; 1">
                <xsl:value-of select="round((count(/details/movie/files/file)+4) div 10)+1"/>
                </xsl:when>
       			<xsl:otherwise>2</xsl:otherwise>
    		</xsl:choose>
		</xsl:variable>
		<xsl:for-each select="files/file[position()&lt;$teiler]">

			<xsl:call-template name="setEpisodeArrays">
			 <xsl:with-param name="count" select="position()" />
			</xsl:call-template>
		</xsl:for-each>
	</xsl:template>


	<xsl:template name="setEpisodeArrays">
		<xsl:param name="count" />
		<xsl:variable name="max" select="$count * 10 +1" />
		<xsl:variable name="min" select="$max - 11" />
		<xsl:variable name="position" select="$count * 10 +1" />


		<script type="text/javascript">
		<xsl:comment>

		<xsl:for-each select="/details/movie/files/file[position()&gt;$min and position()&lt;$max]">
		
		<xsl:variable name="parsedTitle" select="tokenize(@title,' / ')"/>

<xsl:variable name="url">
      <xsl:call-template name="substring-after-last">
        <xsl:with-param name="string" select="fileURL" />
        <xsl:with-param name="delimiter" select="$filePath" />
      </xsl:call-template>
    </xsl:variable>

	   	<xsl:for-each select="filePlot">
        <xsl:variable name="pass" select="position()" />
        <xsl:variable name="shortTitle">
    	  	<xsl:value-of select="substring($parsedTitle[$pass], 1, $tTitleTrunca)"/><xsl:if test="string-length($parsedTitle[$pass]) > $tTitleTrunca">…</xsl:if>
    	  	<xsl:if test="$pass &gt; 1"> (e<xsl:value-of select="@part - $pass +1"/>)</xsl:if>
    		</xsl:variable>

		    <xsl:variable name="plot" select="." />
		    <xsl:variable name="TitleProcessed">
			<xsl:call-template name="search-and-replace">
				<xsl:with-param name="input">
					<xsl:value-of select="@part" />
						<xsl:if test="$parsedTitle[$pass] != '' and $parsedTitle[$pass] !='UNKNOWN'"><xsl:text>. </xsl:text><xsl:value-of select="$parsedTitle[$pass]" /></xsl:if>
					 </xsl:with-param>
					 <xsl:with-param name="search-string">"</xsl:with-param>
					 <xsl:with-param name="replace-string">\"</xsl:with-param>
					</xsl:call-template>

					<xsl:if test="../@lastPart &gt; ../@firstPart"> (e<xsl:value-of select="../@firstPart" /> - e<xsl:value-of select="../@lastPart"/>)</xsl:if>
		   	</xsl:variable>

		    <xsl:variable name="PlotProcessed">
		    	<xsl:variable name="tempPlot">
				 <xsl:if test="$plot != '' and $plot != 'UNKNOWN'">
			      <xsl:value-of select="." />
				 </xsl:if>

			     <xsl:if test="$plot = '' or $plot = 'UNKNOWN'">
			      <xsl:text>Plot unavailable.</xsl:text>
			     </xsl:if>
		     </xsl:variable>
		     <xsl:call-template name="search-and-replace">
					 <xsl:with-param name="input">
					  <xsl:value-of select="substring($tempPlot,1,485)"/>
					 </xsl:with-param>
					 <xsl:with-param name="search-string">"</xsl:with-param>
					 <xsl:with-param name="replace-string">\"</xsl:with-param>
					</xsl:call-template>
		   	</xsl:variable>
		   	asEpisodeTitle.push("<xsl:value-of select="$TitleProcessed"/>");
		   	asEpisodePlot.push("<xsl:value-of select="translate($PlotProcessed,'&#xA;','')"/>");
		   	asEpisodeUrl.push("<xsl:value-of select="$url" />");
		   	asEpisodeNo.push("<xsl:value-of select="@part" />");
		   	asEpisodeTitleShort.push("<xsl:value-of select="translate($shortTitle,'&#32;','&#160;')" />");

	   	</xsl:for-each>

	   	<!-- Add the TV-Show images to the data array -->
	   	<xsl:if test="$mjb.includeVideoImages='true'">
	   		<xsl:for-each select="fileImageFile">
	   		  <xsl:variable name="iPart" select="@part"/>
	   		  <xsl:variable name="sImage">
			      <xsl:choose>
			        <xsl:when test="/details/movie/files/file/fileImageURL[@part=$iPart]!='UNKNOWN'"><xsl:value-of select="."/></xsl:when>
			        <xsl:otherwise>UNKNOWN</xsl:otherwise>
			      </xsl:choose>
			    </xsl:variable>
	    	asEpisodeImage.push("<xsl:value-of select="$sImage"/>");
			  </xsl:for-each>
	   	</xsl:if>

		</xsl:for-each>
		</xsl:comment>
		</script>

	</xsl:template>

	<xsl:template name="substring-before-last">
		<xsl:param name="string" />
		<xsl:param name="delimiter" />
		<xsl:if test="$delimiter and contains($string, $delimiter)">
			<xsl:variable name="temp" select="substring-after($string, $delimiter)" />
			<xsl:value-of select="substring-before($string, $delimiter)" />
			<xsl:if test="contains($temp, $delimiter)">
				<xsl:value-of select="$delimiter" />
				<xsl:call-template name="substring-before-last">
					<xsl:with-param name="string" select="$temp" />
					<xsl:with-param name="delimiter" select="$delimiter" />
				</xsl:call-template>
			</xsl:if>
		</xsl:if>
	</xsl:template>
	<xsl:template name="substring-after-last">
		<xsl:param name="string" />
		<xsl:param name="delimiter" />
		<xsl:choose>
			<xsl:when test="contains($string, $delimiter)">
				<xsl:call-template name="substring-after-last">
					<xsl:with-param name="string" select="substring-after($string, $delimiter)" />
					<xsl:with-param name="delimiter" select="$delimiter" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$string" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="plot">
		<xsl:param name="string" />
		<xsl:param name="delimiter" />
		<xsl:choose>
			<xsl:when test="contains($string, $delimiter)">
				<xsl:call-template name="plot">
					<xsl:with-param name="string" select="substring-before($string,$delimiter)" />
					<xsl:with-param name="delimiter" select="$delimiter" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="$string" />
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>

	<xsl:template name="search-and-replace">
		<xsl:param name="input" />
		<xsl:param name="search-string" />
		<xsl:param name="replace-string" />
		<xsl:choose>
			<xsl:when test="$search-string and contains($input, $search-string)">
				<xsl:value-of select="substring-before($input,$search-string)" />
				<xsl:value-of select="$replace-string" />
				<xsl:call-template name="search-and-replace">
					<xsl:with-param name="input" select="substring-after($input,$search-string)" />
					<xsl:with-param name="search-string" select="$search-string" />
					<xsl:with-param name="replace-string" select="$replace-string" />
				</xsl:call-template>
			</xsl:when>
			<xsl:otherwise><xsl:value-of select="$input" /></xsl:otherwise>
		</xsl:choose>
	</xsl:template>



	<xsl:template name="trailers">
		<!-- Begin Trailers TV -->
		<xsl:if test="count(extras) != 0 and /details/movie/season = -1">
		  <xsl:for-each select="extras/extra">
			  <xsl:if test="position() &lt; 5">
			  <xsl:variable name="tempI"><xsl:if test="$noPrefix.onlyOne = 'true' and count(/details/movie/files/file) &gt; '1' and $multipartmoviehandling = 'classic'"><xsl:value-of select="$trailer.tvid.prefix" /></xsl:if><xsl:value-of select="position()" /></xsl:variable>
			  <div>
			  <xsl:attribute name="class">tabTrailer abs text infoHeadLeft line<xsl:value-of select="position()" /></xsl:attribute>
			  <a>
					<xsl:attribute name="href"><xsl:value-of select="." /></xsl:attribute>
					<!-- 2009-04-17: get Link Attribute by template -->
          <xsl:call-template name="getPlayAttr">
           <xsl:with-param name="fUrl" select="." />
          </xsl:call-template>
					<xsl:attribute name="TVID" select="$tempI"/>
					<xsl:if test="position() = 1">
					<xsl:attribute name="onkeyupset">trailer</xsl:attribute>
					<xsl:attribute name="name">firstTrailer</xsl:attribute>
					</xsl:if>
					<xsl:if test="position() = count(/details/movie/extras/extra) or position() = 4 ">
					<xsl:attribute name="onkeydownset">lastTrailer</xsl:attribute>
					</xsl:if>

					<xsl:value-of select="@title"/> (<xsl:value-of  select="$tempI"/>)

					</a>
					</div>
			  </xsl:if>
				</xsl:for-each>
				<a href="#" onfocusset="firstTrailer" name="lastTrailer"></a>
		</xsl:if>
		<!-- End Trailers TV -->
	</xsl:template>

  <xsl:template name="navigation">
  <!-- Begin Navigation Movie -->
		<xsl:choose>
			<xsl:when test="season = -1">
				<!--Movies-->

				<a class="link">
          <xsl:if test="count(files/file) = '1'">
           <xsl:attribute name="href"><xsl:value-of select="//files/file/fileURL" /></xsl:attribute>
            <!-- 2009-04-17: get Link Attribute by template -->
            <xsl:call-template name="getPlayAttr">
              <xsl:with-param name="fUrl" select="files/file/fileURL" />
            </xsl:call-template>
            <xsl:attribute name="onkeyrightset">red</xsl:attribute>
          </xsl:if>
          <xsl:attribute name="onkeydownset">pagePlayDown</xsl:attribute>
          <xsl:attribute name="onkeyupset">pagePlayUp</xsl:attribute>
          <xsl:attribute name="onfocus">fPlay=true;changePgLink();</xsl:attribute>
          <xsl:attribute name="onblur">fPlay=false;changePgLink();</xsl:attribute>
          <xsl:if test="count(files/file) != '1'">
           <xsl:attribute name="href"><xsl:value-of select="concat(/details/movie/baseFilename,'.playlist.jsp')" /></xsl:attribute>
           <xsl:attribute name="vod">playlist</xsl:attribute>
          </xsl:if>
          <xsl:attribute name="TVID">Play</xsl:attribute>
          <xsl:attribute name="name">Play</xsl:attribute>
          <xsl:if test="//movie/prebuf != '-1'">
           <xsl:attribute name="prebuf"><xsl:value-of select="//movie/prebuf" /></xsl:attribute>
          </xsl:if>
          <img src="pictures/tab_play.png" id="tabPlayImg" onfocussrc="pictures/tab_play_f2.png" onmouseover="this.src='pictures/tab_play_f2.png'" onmouseout="this.src='pictures/tab_play.png'" />
         </a>
			</xsl:when>
			<xsl:otherwise>
			  <a>
          <xsl:if test="count(files/file) != '1'">
            <xsl:attribute name="href"><xsl:value-of select="concat(/details/movie/baseFilename,'.playlist.jsp')" /></xsl:attribute>
            <xsl:attribute name="vod">playlist</xsl:attribute>
          </xsl:if>
          <xsl:if test="count(files/file) = '1'">
            <xsl:attribute name="href"><xsl:value-of select="/details/movie/files/file/fileURL"/></xsl:attribute>
            <xsl:call-template name="getPlayAttr">
              <xsl:with-param name="fUrl" select="/details/movie/files/file/fileURL" />
            </xsl:call-template>
          </xsl:if>
          <xsl:attribute name="id">playlist</xsl:attribute>
          <xsl:attribute name="name">Play</xsl:attribute>
          <img src="pictures/tab_play.png" id="tabPlayImg" onfocussrc="pictures/tab_play_f2.png" onmouseover="this.src='pictures/tab_play_f2.png'" onmouseout="this.src='pictures/tab_play.png'" />
        </a>
			</xsl:otherwise>


		</xsl:choose>
    <!-- END Navigation Movie -->

	</xsl:template>

	<xsl:template name="getEpisodeList">
		<xsl:param name="position" />
		<!--<xsl:variable name="URL" select="../fileImageFile" />-->
		<!--<xsl:variable name="URL" select="concat(substring-before(../fileImageFile,'videoimage'),'playlist.jsp')" />-->
		<!--<xsl:variable name="URL" select="concat(concat(concat(../../../baseFilename,'.playlist'),$position),'.jsp')" />-->

      	<xsl:variable name="epNum" select="count(/details/movie/files/file/filePlot)" />

<xsl:variable name="URL">
	<xsl:choose>
		<xsl:when test="$TVPlaylist='false'">
			<xsl:choose>
				<xsl:when test="//movie/container = 'RAR' or substring(../fileURL,string-length(../fileURL)-3,4) = '.RAR' or substring(../fileURL,string-length(../fileURL)-3,4) = '.rar'">
					<xsl:value-of select="concat(../fileURL,'?playall=1')" />
				</xsl:when>
				<!--<xsl:when test="substring(//files/file/fileURL,string-length(//files/file/fileURL)-9,10) = 'part01.rar' or substring(//files/file/fileURL,string-length(//files/file/fileURL)-9,10) = 'PART01.RAR' or substring(//files/file/fileURL,string-length(//files/file/fileURL)-10,11) = 'part001.rar' or substring(//files/file/fileURL,string-length(//files/file/fileURL)-10,11) = 'PART001.RAR'">
				
				</xsl:when>--><!-- futureproof: when multipart episodes get fixed -->
				<xsl:when test="//movie/container = 'VOB' or substring(../fileURL,string-length(../fileURL)-3,4) = '.VOB' or substring(../fileURL,string-length(../fileURL)-3,4) = '.vob' or //movie/container = 'ISO' or substring(../fileURL,string-length(../fileURL)-3,4) = '.ISO' or substring(../fileURL,string-length(../fileURL)-3,4) = '.iso' or //movie/container = 'IMG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.IMG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.img' or //movie/container = 'MDF' or substring(../fileURL,string-length(../fileURL)-3,4) = '.MDF' or substring(../fileURL,string-length(../fileURL)-3,4) = '.mdf' or //movie/container = 'NRG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.NRG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.nrg' or //movie/container = 'BIN' or substring(../fileURL,string-length(../fileURL)-3,4) = '.BIN' or substring(../fileURL,string-length(../fileURL)-3,4) = '.bin' or //movie/container = 'VIDEO_TS' or substring(../fileURL,string-length(../fileURL)-7,8) = 'VIDEO_TS' or substring(../fileURL,string-length(../fileURL)-7,8) = 'video_ts'">
					<xsl:value-of select="../fileURL" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="../fileURL" />
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>

		<xsl:when test="$TVPlaylist='true' and $epNum!='1' and $ForComputer='false'">
			<xsl:choose>
				<xsl:when test="//movie/container = 'RAR' or substring(../fileURL,string-length(../fileURL)-3,4) = '.RAR' or substring(../fileURL,string-length(../fileURL)-3,4) = '.rar'">
					<xsl:value-of select="concat(../fileURL,'?playall=1')" />
				</xsl:when>
				<xsl:when test="//movie/container = 'VOB' or substring(../fileURL,string-length(../fileURL)-3,4) = '.VOB' or substring(../fileURL,string-length(../fileURL)-3,4) = '.vob' or //movie/container = 'ISO' or substring(../fileURL,string-length(../fileURL)-3,4) = '.ISO' or substring(../fileURL,string-length(../fileURL)-3,4) = '.iso' or //movie/container = 'IMG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.IMG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.img' or //movie/container = 'MDF' or substring(../fileURL,string-length(../fileURL)-3,4) = '.MDF' or substring(../fileURL,string-length(../fileURL)-3,4) = '.mdf' or //movie/container = 'NRG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.NRG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.nrg' or //movie/container = 'BIN' or substring(../fileURL,string-length(../fileURL)-3,4) = '.BIN' or substring(../fileURL,string-length(../fileURL)-3,4) = '.bin' or //movie/container = 'VIDEO_TS' or substring(../fileURL,string-length(../fileURL)-7,8) = 'VIDEO_TS' or substring(../fileURL,string-length(../fileURL)-7,8) = 'video_ts'">
					<xsl:value-of select="../fileURL" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="concat(concat(concat(../../../baseFilename,'.playlist'),../@firstPart),'.jsp')" />
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>

		<xsl:when test="$TVPlaylist='true' and $epNum='1' and $ForComputer='false'">
			<xsl:choose>
				<xsl:when test="//movie/container = 'RAR' or substring(../fileURL,string-length(../fileURL)-3,4) = '.RAR' or substring(../fileURL,string-length(../fileURL)-3,4) = '.rar'">
					<xsl:value-of select="concat(../fileURL,'?playall=1')" />
				</xsl:when>
				<xsl:when test="//movie/container = 'VOB' or substring(../fileURL,string-length(../fileURL)-3,4) = '.VOB' or substring(../fileURL,string-length(../fileURL)-3,4) = '.vob' or //movie/container = 'ISO' or substring(../fileURL,string-length(../fileURL)-3,4) = '.ISO' or substring(../fileURL,string-length(../fileURL)-3,4) = '.iso' or //movie/container = 'IMG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.IMG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.img' or //movie/container = 'MDF' or substring(../fileURL,string-length(../fileURL)-3,4) = '.MDF' or substring(../fileURL,string-length(../fileURL)-3,4) = '.mdf' or //movie/container = 'NRG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.NRG' or substring(../fileURL,string-length(../fileURL)-3,4) = '.nrg' or //movie/container = 'BIN' or substring(../fileURL,string-length(../fileURL)-3,4) = '.BIN' or substring(../fileURL,string-length(../fileURL)-3,4) = '.bin' or //movie/container = 'VIDEO_TS' or substring(../fileURL,string-length(../fileURL)-7,8) = 'VIDEO_TS' or substring(../fileURL,string-length(../fileURL)-7,8) = 'video_ts'">
					<xsl:value-of select="../fileURL" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="../fileURL" />
				</xsl:otherwise>
			</xsl:choose>
		</xsl:when>
		
		<xsl:when test="$TVPlaylist='true' and $ForComputer='true'">
			<xsl:value-of select="../fileURL" />
		</xsl:when>

	</xsl:choose>
</xsl:variable>

<!--
    <xsl:choose>
		  <xsl:when test="lower-case($file-container)='vob' and $nomenus='true'">
        <xsl:attribute name="vod"/>
      </xsl:when>
      <xsl:when test="lower-case($file-container) = 'iso'
            or lower-case($file-container) = 'img'
            or lower-case($file-container) = 'mdf'
            or lower-case($file-container) = 'nrg'
            or lower-case($file-container) = 'bin'">
        <xsl:attribute name="zcd">2</xsl:attribute>
      </xsl:when>
      <xsl:when test="lower-case(substring($fUrl, string-length($fUrl)-7, 8)) = 'video_ts'">
        <xsl:attribute name="zcd">2</xsl:attribute>
        <xsl:attribute name="vod"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:attribute name="vod">playlist</xsl:attribute>
      </xsl:otherwise>
    </xsl:choose>
-->

		<xsl:variable name="episodeTitle" select="tokenize(../@title,' / ')" />

        
			<xsl:variable name="pass" select="@part - ../@firstPart +1" />
      <xsl:variable name="episodeNo">
        <xsl:choose>
  			  <xsl:when test="string-length(@part) = '1'">0<xsl:value-of select="@part"/></xsl:when>
  			  <xsl:otherwise><xsl:value-of select="@part"/></xsl:otherwise>
				</xsl:choose>
			</xsl:variable>

<!--			<xsl:if test="$position &lt; 21">-->

      	<xsl:variable name="posX">
      		<xsl:choose>
      		  <xsl:when test="$position &lt; 6">epLeft</xsl:when>
      		  <xsl:when test="$position &gt; 5 and $position &lt; 11">epMid</xsl:when>
      		  <xsl:when test="$position &gt; 10 and $position &lt; 16">epMid2</xsl:when>
      		  <xsl:otherwise>epRight</xsl:otherwise>
      		</xsl:choose>
      	</xsl:variable>

      	<xsl:variable name="modulo">
      		<xsl:value-of select="$position mod 5" />
      	</xsl:variable>

        <xsl:variable name="posY">
        	<xsl:choose>
      			<xsl:when test="$modulo != 0">
                <xsl:value-of select="$modulo"/>
                </xsl:when>
       			<xsl:otherwise>5</xsl:otherwise>
    		</xsl:choose>
		</xsl:variable>

<!--      	<div>-->
<!--      	<xsl:attribute name="class">tabTvShow abs text <xsl:value-of select="$posX" /> lineTv<xsl:value-of select="$posY" /></xsl:attribute>-->
      	  <a class="TvLink">
						<xsl:attribute name="href"><xsl:value-of select="$URL"/></xsl:attribute>
            <xsl:call-template name="getPlayAttr">
              <xsl:with-param name="fUrl" select="$URL" />
            </xsl:call-template>
						<xsl:attribute name="id">a_e_<xsl:value-of select="$position"/></xsl:attribute>
						<xsl:attribute name="name">episode<xsl:value-of select="$position"/></xsl:attribute>
						
						<xsl:if test="$position='1'">
						<xsl:attribute name="onkeyleftset">episode<xsl:value-of select="$epNum"/></xsl:attribute>
						</xsl:if>
						<xsl:if test="$position!='1'">
						<xsl:attribute name="onkeyleftset">episode<xsl:value-of select="($position)-1"/></xsl:attribute>
						</xsl:if>
						<xsl:if test="$position!=$epNum">
						<xsl:attribute name="onkeyrightset">episode<xsl:value-of select="($position)+1"/></xsl:attribute>
						</xsl:if>
						<xsl:if test="$position=$epNum">
						<xsl:attribute name="onkeyrightset">episode1</xsl:attribute>
						</xsl:if>
						
						<xsl:attribute name="onkeyupset">Play</xsl:attribute>
						<xsl:attribute name="onkeydownset">Play</xsl:attribute>
						
<!--						<xsl:if test="$position='1'">
						<xsl:attribute name="onkeyupset">episode<xsl:value-of select="count(/details/movie/files/file)"/></xsl:attribute>
						</xsl:if>
						<xsl:if test="$position!='1'">
						<xsl:attribute name="onkeyupset">episode<xsl:value-of select="($position)-1"/></xsl:attribute>
						</xsl:if>
						<xsl:if test="$position!=count(/details/movie/files/file)">
						<xsl:attribute name="onkeydownset">episode<xsl:value-of select="($position)+1"/></xsl:attribute>
						</xsl:if>
						<xsl:if test="$position=count(/details/movie/files/file)">
						<xsl:attribute name="onkeydownset">episode1</xsl:attribute>
						</xsl:if>
						
						<xsl:attribute name="onkeyrightset">Play</xsl:attribute>
						<xsl:attribute name="onkeyleftset">Play</xsl:attribute>-->

						<xsl:attribute name="onfocus">showEpisode(<xsl:value-of select="$position"/>)</xsl:attribute>
						<xsl:if test="$showPlotwithBtn = 'true'">
						  <xsl:attribute name="onblur">hideEpisode()</xsl:attribute>
						</xsl:if>
						<xsl:attribute name="onmouseover">showEpisode(<xsl:value-of select="$position"/>)</xsl:attribute>
<!--						<xsl:choose>
						  <xsl:when test="$position = 1">
                <xsl:attribute name="onkeyupset">yellow</xsl:attribute>
						  </xsl:when>
						  <xsl:when test="$position = 20 or $position = $epNum">
                <xsl:attribute name="onkeydownset">episode1</xsl:attribute>
						  </xsl:when>
						  <xsl:when test="$posY = 1 and $position &gt; 1">
						    <xsl:attribute name="onkeyupset">episode<xsl:value-of select="$position - 1"/></xsl:attribute>
						  </xsl:when>
						  <xsl:when test="$posY = 5 and $position &lt; 20">
						    <xsl:attribute name="onkeydownset">episode<xsl:value-of select="$position + 1"/></xsl:attribute>
						  </xsl:when>
						  <!**
						  <xsl:when test="$posY = 5 and $position= 20">
						    <xsl:attribute name="onkeydownset">scrollDown</xsl:attribute>
						  </xsl:when>
						  **>
						</xsl:choose>-->

						<!-- Navigation RIGHT for the last 5 Links  -->
<!--						<xsl:choose>
						  <xsl:when test="$epNum &gt;= 20 and $posX='epRight'">
                <xsl:attribute name="onkeyrightset">episode<xsl:value-of select="$position - 15"/></xsl:attribute>
						  </xsl:when>
						  <xsl:when test="$epNum &lt;= 20 and $position &gt; 5 and $position &gt;= $epNum - 4 ">
                <xsl:attribute name="onkeyrightset">episode<xsl:value-of select="$posY"/></xsl:attribute>
						  </xsl:when>
						</xsl:choose>-->

						<!-- Navigation LEFT for Link 1-5  -->
<!--						<xsl:choose>
						  <xsl:when test="$epNum &gt;= 20 and $position &lt; 6">
                <xsl:attribute name="onkeyleftset">episode<xsl:value-of select="$position + 15"/></xsl:attribute>
						  </xsl:when>
						  <xsl:when test="$epNum &lt;= 20 and $position &lt; 6">
						    <xsl:choose>
								  <xsl:when test="$epNum &gt;= 15">
								    <xsl:if test="$position + 15 &lt;= $epNum"><xsl:attribute name="onkeyleftset">episode<xsl:value-of select="$position + 15"/></xsl:attribute></xsl:if>
								    <xsl:if test="$position + 15 &gt; $epNum"><xsl:attribute name="onkeyleftset">episode<xsl:value-of select="$position + 10"/></xsl:attribute></xsl:if>
								  </xsl:when>
								  <xsl:when test="$epNum &gt;= 10">
		                <xsl:if test="$position + 10 &lt;= $epNum"><xsl:attribute name="onkeyleftset">episode<xsl:value-of select="$position + 10"/></xsl:attribute></xsl:if>
								    <xsl:if test="$position + 10 &gt; $epNum"><xsl:attribute name="onkeyleftset">episode<xsl:value-of select="$position + 5"/></xsl:attribute></xsl:if>
								  </xsl:when>
								  <xsl:otherwise>
								    <xsl:if test="$position + 5 &lt;= $epNum"><xsl:attribute name="onkeyleftset">episode<xsl:value-of select="$position + 5"/></xsl:attribute></xsl:if>
								  </xsl:otherwise>
								</xsl:choose>
						  </xsl:when>
						</xsl:choose>-->


<!--						<span class="tabTvShow">
    					<xsl:attribute name="id">s_e_<xsl:value-of select="$position"/></xsl:attribute>-->
    					<xsl:choose>
    						<xsl:when test="$show_episode_names='true'">
								<xsl:if test="$ForComputer='false'">
    								<img src="pictures/1x1.png"/>
								</xsl:if>
								<xsl:if test="$ForComputer='true'">
    								<xsl:value-of select="$episodeNo"/>&#160; 
								</xsl:if>
<!--.
            			<xsl:call-template name="truncate_phrase">
            			 	<xsl:with-param name="phrase">
            			  <xsl:value-of select="$episodeTitle[$pass]"/>
            			 	</xsl:with-param>
            			 	<xsl:with-param name="length" select="$tTitleTrunca" />
            		 		<xsl:with-param name="truncate_to_word_boundary" select="1" />
            	  	</xsl:call-template>
            	  	<xsl:if test="$pass &gt; 1"> (e<xsl:value-of select="@part - $pass +1"/>)</xsl:if>-->
    						</xsl:when>
    						<xsl:otherwise>
    							<xsl:choose>
    								<xsl:when test="string-length(//movie/season) = '1'">s0<xsl:value-of select="//movie/season"/></xsl:when>
    								<xsl:otherwise>s<xsl:value-of select="//movie/season"/></xsl:otherwise>
    							</xsl:choose>e<xsl:value-of select="$episodeNo"/>
    						</xsl:otherwise>
    					</xsl:choose>
<!--						<img src="pictures/epoff.png" onfocussrc="pictures/epon.png"></img>&#160; -->
<!--  					</span>-->
					</a><xsl:if test="$ForComputer='false'"><br></br></xsl:if>
					<!-- TODO hier mal schauen, ob das nicht besser geht onloadset usw... -->
					<a href="#" class="tabTvShow">
						<xsl:attribute name="TVID"><xsl:value-of select="@part"/></xsl:attribute>
						<xsl:attribute name="onclick">setFocus(<xsl:value-of select="$position"/>); return false;</xsl:attribute>
						<xsl:attribute name="id">t_e_<xsl:value-of select="$position"/></xsl:attribute>
					</a>

<!--      	</div>-->

<!--      </xsl:if>-->

	</xsl:template>

  <xsl:template name="getPlayAttr">
    <xsl:param name="fUrl"></xsl:param>
    <xsl:variable name="file-container">
      <xsl:call-template name="substring-after-last">
        <xsl:with-param name="string" select="$fUrl" />
        <xsl:with-param name="delimiter" select="'.'" />
      </xsl:call-template>
    </xsl:variable>

    <xsl:choose>
		  <xsl:when test="translate($file-container,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='vob' and $nomenus='true'">
        <xsl:attribute name="vod"/>
      </xsl:when>
      <xsl:when test="translate($file-container,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'iso'
            or translate($file-container,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'img'
            or translate($file-container,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'mdf'
            or translate($file-container,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'nrg'
            or translate($file-container,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'bin'">
        <xsl:attribute name="zcd">2</xsl:attribute>
      </xsl:when>
      <xsl:when test="translate(substring($fUrl, string-length($fUrl)-7, 8),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'video_ts'">
        <xsl:attribute name="zcd">2</xsl:attribute>
        <xsl:attribute name="vod"/>
      </xsl:when>
      <xsl:otherwise>

<xsl:choose>
<xsl:when test="$TVPlaylist='false'">
	<xsl:choose>
		<xsl:when test="//movie/container = 'RAR' or substring(../fileURL,string-length(../fileURL)-3,4) = '.RAR' or substring(../fileURL,string-length(../fileURL)-3,4) = '.rar'">
			<xsl:attribute name="vod">playlist</xsl:attribute>
		</xsl:when>
		<xsl:otherwise>
			<xsl:attribute name="vod" />
		</xsl:otherwise>
	</xsl:choose>
</xsl:when>
<xsl:when test="$TVPlaylist='true' and count(/details/movie/files/file/filePlot)!='1'">
<xsl:attribute name="vod">playlist</xsl:attribute>
</xsl:when>
<xsl:when test="$TVPlaylist='true' and count(/details/movie/files/file/filePlot)='1'">
<xsl:attribute name="vod"/>
</xsl:when>
</xsl:choose>
	  
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template name="imdbRating">
    <xsl:if test="rating != -1">
     <xsl:if test="$star_rating = 'true'">
      <div>
       <img><xsl:attribute name="src">pictures/detail/rating_<xsl:value-of select="round(rating div 10)*10" />.png</xsl:attribute></img>
      </div>
     </xsl:if>
     <xsl:if test="$full_rating = 'true'">
      <xsl:if test="$star_rating = 'true'">
       <div class="gold">
        IMDb: <xsl:value-of select="rating div 10" />/10
       </div>
      </xsl:if>
      <xsl:if test="$star_rating = 'false'">
       <div class="gold">
        IMDb: <xsl:value-of select="rating div 10" />/10
       </div>
      </xsl:if>
     </xsl:if>
    </xsl:if>
  </xsl:template>


  <xsl:template name="infoTabContent">
    <!-- left -->

    <div class="tabInfo abs headline infoHeadLeft screen">Source</div>
    <div class="tabInfo abs text infoTextLeft screenText"><xsl:call-template name="video-source" /></div>

    <div class="tabInfo abs headline infoHeadLeft size line2">Size</div>
    <div class="tabInfo abs text infoTextLeft sizeText line2Text"><xsl:call-template name="template-resolution" /></div>

    <div class="tabInfo abs headline infoHeadLeft audio line4">Audio</div>
    <div id="audioDiv" class="tabInfo abs text infoTextLeft audioText line4Text">
      <xsl:call-template name="audio-codec" />
     </div>

    <div class="tabInfo abs headline infoHeadLeft output line3">Output</div>
    <div class="tabInfo abs text infoTextLeft outputText line3Text">
   		<xsl:call-template name="template-videoOutput-text" />
  	</div>

    <!-- middle -->
    <div class="tabInfo abs headline infoHeadMid subtitles line1">Subtitles</div>
    <div class="tabInfo abs text subtitlesText line1Text"><xsl:call-template name="template-subtitles" /></div>

  	<div class="tabInfo abs headline infoHeadMid video">Video</div>
    <div class="tabInfo abs text infoTextMid videoText"><xsl:call-template name="video-codec" /></div>

    <div class="tabInfo abs headline infoHeadMid fps line3">Fps</div>
    <div class="tabInfo abs text infoTextMid fpsText line3Text">
   		<xsl:value-of select="fps" />
  	</div>

    <!-- right -->
    <xsl:if test="libraryDescription != 'UNKNOWN'">
      <div class="tabInfo abs headline infoHeadRight library line1">Library</div>
      <div class="tabInfo abs text infoTextRight libraryText line1Text">
        <!-- get libraryDescription title from template -->
      	<xsl:call-template name="template-libraryDescription" />
    	</div>
  	</xsl:if>
  </xsl:template>

<!--  <xsl:template name="poster">
    <div id="imageDiv" class="abs poster hidden"><img id="image"><xsl:attribute name="src" select="detailPosterFile"  /><xsl:attribute name="width" select="$posters.width"  /></img></div>
  </xsl:template>-->
</xsl:stylesheet>
